﻿### Various Tasks ###

grand_consort_task_instill_virtues = {
	court_position_types = { grand_consort_court_position }

	# Monthly cost for the task
	cost = {
		round = no
		gold = {
			add = {
				value = monthly_court_position_task_cost
				desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
				format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
			}
		}
	}

	is_valid_showing_failures_only = { 
		scope:liege = {
			custom_tooltip = {
				any_consort = {
					is_courtier_of = prev
					is_imprisoned = no
					count >= 4
				}
				text = grand_consort_tasks_consort_limit_tooltip
			}
		}
	}

	base_employer_modifier = {
	}

	scaling_employer_modifiers = {
		terrible = {
			monthly_prestige = 0.05
		}
		poor = {
			monthly_prestige = 0.05
			stress_loss_mult = 0.05
		}
		average = {
			monthly_prestige = 0.1
			stress_loss_mult = 0.1
			court_grandeur_baseline_add = 4
		}
		good = {
			monthly_prestige = 0.15
			stress_loss_mult = 0.1
			court_grandeur_baseline_add = 6
		}
		excellent = {
			monthly_prestige = 0.2
			stress_loss_mult = 0.15
			court_grandeur_baseline_add = 8
		}
	}

	employee_modifier = {
		diplomacy = 1
		learning = 1
		owned_personal_scheme_success_chance_growth_add = 5
	}

	on_start = {
		custom_tooltip = grand_consort_task_instill_virtues_fallback_tt
	}

	on_monthly = {
		save_scope_as = grand_consort_position_holder
		liege_or_court_owner = { save_scope_as = notification_character }
		scope:notification_character = {
			random_list = {
				11 = { #Success
					#Number of consorts
					modifier = {
						scope:notification_character = {
							any_consort = {
								is_courtier_of = prev
								is_imprisoned = no
								count >= 7
							}
						}
						add = 2
					}
					#High aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position >= 4
							}
						}	
						add = {
							value = 4
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = 2
							}
						}
					}
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 5
							}
						}	
						add = {
							value = 3
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = 2
							}
						}
					}

					#Low aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position <= 2
							}
						}	
						add = {
							value = -4
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = -2
							}
						}
					}
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 1
							}
						}	
						add = {
							value = -3
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = -2
							}
						}
					}

					#Poet trait
					modifier = {
						scope:grand_consort_position_holder = {
							has_trait = poet
						}
						add = {
							value = 1
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = 1
							}
						}
					}
					
					random_list = {
						97 = {
							random_consort = {
								limit = {
									is_courtier_of = scope:notification_character
									is_imprisoned = no	
								}
								weight = {
									base = 10
									modifier = { #Already affected
										add = -4
										has_character_flag = had_grand_consort_effect_flag
									}
									modifier = { #The PS won't receive instructions from a subordinate
										add = -6
										exists = scope:notification_character.primary_spouse
										this = scope:notification_character.primary_spouse
									}
									modifier = { #The GC will prioritize themself
										add = 5
										has_court_position = grand_consort_court_position
									}
									modifier = { #Education
										add = 1
										OR = {
											has_trait = education_diplomacy_1
											has_trait = education_learning_1
										}
									}
									modifier = { #Education
										add = 2
										OR = {
											has_trait = education_diplomacy_2
											has_trait = education_learning_2
										}
									}
									modifier = { #Education
										add = 3
										OR = {
											has_trait = education_diplomacy_3
											has_trait = education_learning_3
										}
									}
									modifier = { #Education
										add = 4
										OR = {
											has_trait = education_diplomacy_4
											has_trait = education_learning_4
											has_trait = education_diplomacy_5
											has_trait = education_learning_5
										}
									}
									modifier = { #Intellect and beauty
										add = 2
										OR = {
											has_trait = intellect_good_1
											has_trait = beauty_good_1
										}
									}
									modifier = { #Intellect and beauty
										add = 3
										OR = {
											has_trait = intellect_good_2
											has_trait = beauty_good_2
										}
									}
									modifier = { #Intellect and beauty
										add = 4
										OR = {
											has_trait = intellect_good_3
											has_trait = beauty_good_3
										}
									}
			
									modifier = { #Low skills
										add = 3
										OR = {
											diplomacy <= medium_skill_rating
											learning <= medium_skill_rating
										}
									}
			
									modifier = { #Intellect and beauty
										add = -2
										has_trait = intellect_bad_1
									}
									modifier = { #Intellect and beauty
										add = -3
										has_trait = intellect_bad_2
									}
									modifier = { #Intellect and beauty
										add = -4
										has_trait = intellect_bad_3
									}
			
									modifier = { #Intellect and beauty
										add = -1
										has_trait = beauty_bad_1
									}
									modifier = { #Intellect and beauty
										add = -2
										has_trait = intellect_bad_2
									}
									modifier = { #Intellect and beauty
										add = -3
										has_trait = intellect_bad_3
									}
			
									modifier = { #Newcomers are more likely to be affected
										add = 10
										has_character_flag = flag_new_consort
									}
									modifier = { #Young consorts are more likely to be affected
										add = 10
										age <= 22
									}
									modifier = {
										add = -8
										hp_accepts_harems = no
									}

									#Instructing someone they like more
									opinion_modifier = {
										who = scope:grand_consort_position_holder
										opinion_target = this
										min = -15
										max = 15
										multiplier = 0.30
									}
								}
								save_scope_as = consort_1
							}
							if = {
								limit = {
									exists = scope:consort_1
								}
								scope:consort_1 = {
									add_character_flag = {
										flag = had_grand_consort_effect_flag
										years = 1
									}
									# Skill improvement
									random_list = {
										50 = { #Learning
											modifier = { # Learning
												add = learning
											}
											modifier = { # Grand Consort's Learning
												add = scope:grand_consort_position_holder.learning
											}
											modifier = { #Traits
												has_trait = education_learning_1
												add = 10
											}
											modifier = { #Traits
												has_trait = education_learning_2
												add = 15
											}
											modifier = { #Traits
												OR = {	
													has_trait = education_learning_3
													has_trait = education_learning_4
													has_trait = education_learning_5
												}
												add = 20
											}
											
											modifier = { #Intellect
												add = 10
												has_trait = intellect_good_1
											}
											modifier = { #Intellect
												add = 15
												has_trait = intellect_good_2
											}
											modifier = { #Intellect
												add = 20
												has_trait = intellect_good_3
											}
											modifier = { #Already affected
												add = -2
												has_character_flag = had_positive_learning_flag
											}
											add_learning_skill = 1
											if = {
												limit = {
													NOT = {
														knows_language_of_culture = scope:notification_character.culture
													}
													learning >= 10
												}
												random = {
													chance = 20
													modifier = { # Learning
														add = {
															value = learning
															multiply = 1.5
														}
													}
													learn_language_of_culture = scope:notification_character.culture
													set_local_variable = {
														name = learned_language_of_culture
														value = yes
													}
												}
											}
											if = {
												limit = {
													scope:notification_character.faith = {
														NOT = {
															this = scope:consort_1.faith
														}
														this = scope:grand_consort_position_holder.faith
													}
												}
												random = {
													chance = 20
													modifier = { # Zeal
														add = {
															value = ai_zeal
															multiply = -0.2
														}
													}
													modifier = { # Greed
														add = {
															value = ai_greed
															multiply = 0.1
														}
													}
													modifier = { # Liege's zeal
														add = {
															value = scope:notification_character.ai_zeal
															multiply = 0.1
														}
													}
													modifier = { # Ambition
														has_trait = ambitious
														add = 10
													}
													modifier = { # Arrogance
														has_trait = arrogant
														add = 5
													}
													modifier = {
														faith = {
															faith_hostility_level = {
																target = scope:notification_character.faith
																value = faith_fully_accepted_level
															}
														}
														add = 10
													}
													modifier = {
														faith = {
															faith_hostility_level = {
																target = scope:notification_character.faith
																value >= faith_astray_level
															}
														}
														add = -5
													}
													modifier = {
														faith = {
															faith_hostility_level = {
																target = scope:notification_character.faith
																value >= faith_hostile_level
															}
														}
														add = -5
													}
													modifier = {
														faith = {
															faith_hostility_level = {
																target = scope:notification_character.faith
																value >= faith_evil_level
															}
														}
														add = -5
													}
													set_character_faith = scope:notification_character.faith
													set_local_variable = {
														name = converted_to_liege_faith
														value = yes
													}
												}
											}
											add_character_flag = {
												flag = had_positive_learning_flag
												years = 1
											}
											if = {
												limit = {
													scope:notification_character = {
														is_ai = no
													}
												}
												scope:notification_character = {
													send_interface_toast = {
														type = event_generic_good
														title = successful_consort_skills_t
														left_icon = scope:consort_1
														right_icon = scope:grand_consort_position_holder
														custom_tooltip = successful_consort_skills_desc
														show_as_tooltip = {
															scope:consort_1 = {
																add_learning_skill = 1
																if = {
																	limit = { exists = local_var:learned_language_of_culture }
																	learn_language_of_culture = scope:notification_character.culture
																}
																if = {
																	limit = { exists = local_var:converted_to_liege_faith }
																	set_character_faith = scope:notification_character.faith
																}
															}
														}
													}
												}
											}
										}
										50 = { #Diplomacy
											modifier = { # Diplomacy
												add = diplomacy
											}
											modifier = { # Grand Consort's Diplomacy
												add = scope:grand_consort_position_holder.diplomacy
											}
											modifier = { #Traits
												has_trait = education_diplomacy_1
												add = 10
											}
											modifier = { #Traits
												has_trait = education_diplomacy_2
												add = 15
											}
											modifier = { #Traits
												OR = {	
													has_trait = education_diplomacy_3
													has_trait = education_diplomacy_4
													has_trait = education_diplomacy_5
												}
												add = 20
											}
											
											modifier = { #Beauty
												add = 10
												has_trait = beauty_good_1
											}
											modifier = { #Intellect
												add = 15
												has_trait = beauty_good_2
											}
											modifier = { #Intellect
												add = 20
												has_trait = beauty_good_3
											}
	
											modifier = { #Traits
												add = 5
												has_trait = gregarious
											}
											modifier = { #Traits
												add = -5
												has_trait = shy
											}
											modifier = { #Traits
												add = -5
												has_trait = craven
											}
											modifier = { #Already affected
												add = -2
												has_character_flag = had_positive_diplomacy_flag
											}
											add_diplomacy_skill = 1
											add_character_flag = {
												flag = had_positive_diplomacy_flag
												years = 1
											}
											if = {
												limit = {
													scope:notification_character = {
														is_ai = no
													}
												}
												scope:notification_character = {
													send_interface_toast = {
														type = event_generic_good
														title = successful_consort_skills_t
														left_icon = scope:consort_1
														right_icon = scope:grand_consort_position_holder
														custom_tooltip = successful_consort_skills_desc
														show_as_tooltip = {
															scope:consort_1 = {
																add_diplomacy_skill = 1
															}
														}
													}
												}
											}
										}
										5 = { #Become a poet
											trigger = {
												OR = {
													diplomacy >= high_skill_rating
													learning >= high_skill_rating
												}
												NOR = {
													has_trait = poet
													has_trait = intellect_bad
													scope:notification_character = {
														any_consort = {
															is_courtier_of = prev
															has_trait = poet
															count >= 2
														}
													}
												}
											}
											#Poet trait
											modifier = {
												scope:grand_consort_position_holder = {
													has_trait = poet
												}
												add = 2
											}
											modifier = {
												scope:grand_consort_position_holder = {
													has_trait = intellect_good_1
												}
												add = 2
											}
											modifier = {
												scope:grand_consort_position_holder = {
													has_trait = intellect_good_2
												}
												add = 4
											}
											modifier = {
												scope:grand_consort_position_holder = {
													has_trait = intellect_good_3
												}
												add = 6
											}
											modifier = { #Skills
												add = 5
												OR = {
													diplomacy >= very_high_skill_rating
													learning >= very_high_skill_rating
												}
											}
											modifier = { #Education
												add = 5
												OR = {	
													has_trait = education_learning_4
													has_trait = education_diplomacy_4
													has_trait = education_learning_5
													has_trait = education_diplomacy_5
												}
											}
											modifier = { #Intellect
												add = 5
												has_trait = intellect_good_1
											}
											modifier = { #Intellect
												add = 10
												has_trait = intellect_good_2
											}
											modifier = { #Intellect
												add = 15
												has_trait = intellect_good_3
											}
											add_trait = poet
			
											if = {
												limit = {
													scope:notification_character = {
														is_ai = no
													}
												}
												scope:notification_character = {
													send_interface_toast = {
														type = event_generic_good
														title = successful_consort_skills_t
														left_icon = scope:consort_1
														right_icon = scope:grand_consort_position_holder
														custom_tooltip = successful_consort_skills_desc
														custom_tooltip = successful_consort_poet_desc
													}
												}
											}
										}
									}
								}
							}
						}
						3 = {
							trigger = {
								NOR = {
									has_trait = poet
									has_trait = intellect_bad
								}
							}
							#Poet trait
							modifier = {
								scope:grand_consort_position_holder = {
									has_trait = poet
								}
								add = 2
							}
							modifier = {
								scope:grand_consort_position_holder = {
									has_trait = intellect_good_1
								}
								add = 2
							}
							modifier = {
								scope:grand_consort_position_holder = {
									has_trait = intellect_good_2
								}
								add = 4
							}
							modifier = {
								scope:grand_consort_position_holder = {
									has_trait = intellect_good_3
								}
								add = 6
							}
							modifier = { #Skills
								add = 5
								OR = {
									diplomacy >= very_high_skill_rating
									learning >= very_high_skill_rating
								}
							}
							modifier = { #Education
								add = 5
								OR = {	
									has_trait = education_learning_4
									has_trait = education_diplomacy_4
									has_trait = education_learning_5
									has_trait = education_diplomacy_5
								}
							}
							modifier = { #Intellect
								add = 5
								has_trait = intellect_good_1
							}
							modifier = { #Intellect
								add = 10
								has_trait = intellect_good_2
							}
							modifier = { #Intellect
								add = 15
								has_trait = intellect_good_3
							}
							hidden_effect = {
								add_trait = poet
								if = {
									limit = {
										is_ai = no
									}
									send_interface_toast = {
										type = event_generic_good
										title = successful_consort_skills_t
										right_icon = scope:grand_consort_position_holder
										custom_tooltip = successful_consort_skills_desc
										custom_tooltip = successful_employer_poet_desc
									}
								}
							}

						}
					}
				}
				5 = { #Failure
					#Number of consorts
					modifier = {
						scope:notification_character = {
							any_consort = {
								is_courtier_of = prev
								is_imprisoned = no
								count >= 7
							}
						}
						add = 2
					}
					#High aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position >= 4
							}
						}
						add = {
							value = -4
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = -2
							}
						}
					}
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 5
							}
						}
						add = {
							value = -3
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = -2
							}
						}
					}

					#Low aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position <= 2
							}
						}
						add = {
							value = 7
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = 2
							}
						}
					}
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 1
							}
						}
						add = {
							value = 6
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = 2
							}
						}
					}
					
					random_consort = {
						limit = {
							is_courtier_of = scope:notification_character
							is_imprisoned = no	
							NOR = {
								has_character_modifier = poor_tutelage_modifier
								has_character_modifier = misguided_diplomacy_modifier
							}
						}
						weight = {
							base = 10
							modifier = { #Already affected
								add = -4
								has_character_flag = had_grand_consort_effect_flag
							}
							modifier = { #Low skills
								add = 3
								OR = {
									diplomacy <= medium_skill_rating
									learning <= medium_skill_rating
								}
							}
							modifier = { #Low skills
								add = 3
								OR = {
									diplomacy <= mediocre_skill_rating
									learning <= mediocre_skill_rating
								}
							}
							modifier = { #Low skills
								add = 3
								OR = {
									diplomacy <= low_skill_rating
									learning <= low_skill_rating
								}
							}
	
							modifier = { #Intellect and beauty
								add = 2
								has_trait = intellect_bad_1
							}
							modifier = { #Intellect and beauty
								add = 3
								has_trait = intellect_bad_2
							}
							modifier = { #Intellect and beauty
								add = 4
								has_trait = intellect_bad_3
							}
	
							modifier = { #Intellect and beauty
								add = 1
								has_trait = beauty_bad_1
							}
							modifier = { #Intellect and beauty
								add = 2
								has_trait = intellect_bad_2
							}
							modifier = { #Intellect and beauty
								add = 3
								has_trait = intellect_bad_3
							}
							
							modifier = { #Newcomers are more likely to be affected
								add = 10
								has_character_flag = flag_new_consort
							}
							modifier = { #Young consorts are more likely to be affected
								add = 10
								age <= 22
							}
							modifier = {
								add = 8
								hp_accepts_harems = no
							}

							#Ruining someone they don't like
							opinion_modifier = {
								who = scope:grand_consort_position_holder
								opinion_target = this
								min = -15
								max = 15
								multiplier = -0.30
							}
						}
						save_scope_as = consort_1
					}
					if = {
						limit = {
							exists = scope:consort_1
						}
						scope:consort_1 = {
							add_character_flag = {
								flag = had_grand_consort_effect_flag
								years = 1
							}
							random_list = {
								50 = { #Learning
									modifier = { #Traits
										has_trait = education_learning_1
										add = 15
									}
									modifier = { #Traits
										has_trait = education_learning_2
										add = 10
									}
									
									modifier = { #Intellect
										add = 10
										has_trait = intellect_bad_1
									}
									modifier = { #Intellect
										add = 15
										has_trait = intellect_bad_2
									}
									modifier = { #Intellect
										add = 20
										has_trait = intellect_bad_3
									}
									modifier = { #Already affected
										add = -5
										has_character_modifier = poor_tutelage_modifier
									}
									add_character_modifier = {
										modifier = poor_tutelage_modifier
										years = 1
									}
									if = {
										limit = {
											scope:notification_character = {
												is_ai = no
											}
										}
										scope:notification_character = {
											send_interface_toast = {
												type = event_generic_bad
												title = failure_consort_skills_t
												left_icon = scope:consort_1
												right_icon = scope:grand_consort_position_holder
												custom_tooltip = failure_consort_skills_desc
												show_as_tooltip = {
													scope:consort_1 = {
														add_character_modifier = {
															modifier = poor_tutelage_modifier
															years = 1
														}
													}
												}
											}
										}
									}
								}
								50 = { #Diplomacy
									modifier = { #Traits
										has_trait = education_diplomacy_1
										add = 15
									}
									modifier = { #Traits
										has_trait = education_diplomacy_2
										add = 10
									}
									
									modifier = { #Beauty
										add = 10
										has_trait = beauty_bad_1
									}
									modifier = { #Beauty
										add = 15
										has_trait = beauty_bad_2
									}
									modifier = { #Beauty
										add = 20
										has_trait = beauty_bad_3
									}
									modifier = { #Already affected
										add = -5
										has_character_modifier = misguided_diplomacy_modifier
									}
									add_character_modifier = {
										modifier = misguided_diplomacy_modifier
										years = 1
									}
									if = {
										limit = {
											scope:notification_character = {
												is_ai = no
											}
										}
										scope:notification_character = {
											send_interface_toast = {
												type = event_generic_bad
												title = failure_consort_skills_t
												left_icon = scope:consort_1
												right_icon = scope:grand_consort_position_holder
												custom_tooltip = failure_consort_skills_desc
												show_as_tooltip = {
													scope:consort_1 = {
														add_character_modifier = {
															modifier = misguided_diplomacy_modifier
															years = 1
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
				85 = { #Nothing
					#Number of consorts
					modifier = {
						scope:notification_character = {
							any_consort = {
								is_courtier_of = prev
								is_imprisoned = no
								count >= 7
							}
						}
						add = -4
					}

					#Poet trait
					modifier = {
						scope:grand_consort_position_holder = {
							has_trait = poet
						}
						add = {
							value = -1
							if = {
								limit = {
									scope:notification_character = {
										any_consort = {
											is_courtier_of = prev
											is_imprisoned = no
											count >= 7
										}
									}
								}
								add = -1
							}
						}
					}

					modifier = {
						NOT = {
							any_consort = {
								OR = {
									diplomacy <= high_skill_rating
									learning <= high_skill_rating
								}
							}
						}
						add = 13
					}
				}
			}
		}
	}

	on_yearly = {
		save_scope_as = grand_consort_position_holder
		liege_or_court_owner = { save_scope_as = notification_character }
		scope:notification_character = {
			random_list = {
				8 = { #Impressing a neighboring ruler
					trigger = {
						any_neighboring_top_liege_realm_owner = {
							harem_politics_grand_consort_task_valid_neighboring_ruler_trigger = {
								OVERLORD = scope:notification_character
							}
						}
					}
					#High aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position >= 4
							}
						}	
						add = {
							value = 1
							if = {
								limit = {
									scope:notification_character = {
										any_court_position_holder = {
											type = grand_consort_court_position
											aptitude:grand_consort_court_position = 5
										}
									}	
								}
								add = 1
							}
						}
					}

					#Low aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position <= 2
							}
						}	
						add = {
							value = -1
							if = {
								limit = {
									scope:notification_character = {
										any_court_position_holder = {
											type = grand_consort_court_position
											aptitude:grand_consort_court_position = 1
										}
									}
								}
								add = -1
							}
						}
					}

					modifier = { #Hostile faiths
						any_neighboring_top_liege_realm_owner = {
							faith = {
								faith_hostility_level = {
									target = scope:notification_character.faith
									value >= faith_astray_level
								}
							}
							max_military_strength >= scope:notification_charactermax_military_strength
							harem_politics_grand_consort_task_valid_neighboring_ruler_trigger = {
								OVERLORD = scope:notification_character
							}
						}
						add = 4
					}
					random_neighboring_top_liege_realm_owner = {
						limit = {
							harem_politics_grand_consort_task_valid_neighboring_ruler_trigger = {
								OVERLORD = scope:notification_character
							}
						}
						weight = {
							base = 10
							modifier = { #Tier difference
								tier_difference = {
									target = scope:notification_character
									value >= 0
								}
								add = {
									value = 10
									if = {
										limit = {
											tier_difference = {
												target = scope:notification_character
												value >= 1
											}
										}
										add = 10
									}
								}
							}
							opinion_modifier = { #Opinion
								WHO = this
								opinion_target = scope:notification_character
								multiplier = -0.5
							}
							modifier = { #Faith hostility
								faith = {
									faith_hostility_level = {
										target = scope:notification_character.faith
										value >= faith_astray_level
									}
								}
								add = {
									value = 5
									if = {
										limit = {
											faith = {
												faith_hostility_level = {
													target = scope:notification_character.faith
													value >= faith_hostile_level
												}
											}
										}
										add = 5
									}
								}
							}
							modifier = { #Claimants
								any_claim = {
									tier >= tier_county
									any_de_jure_top_liege = {
										this = scope:notification_character
									}
								}
								add = 5
							}
							modifier = { #Monogamous characters are more intrigued by rulers with many consorts
								hp_accepts_harems = no
								add = 5
							}
							modifier = { #Strong rulers
								max_military_strength >= scope:notification_charactermax_military_strength
								add = 20
							}
							modifier = { #Captured their relative
								has_opinion_modifier = {
									modifier = forced_family_concubine_marriage_opinion
									target = scope:notification_character
								}
								add = 10
							}
							modifier = { #Enemies
								OR = {
									has_relation_rival = scope:notification_character
									has_relation_nemesis = scope:notification_character
								}
								add = 10
							}
							modifier = { #Suzerains won't invade us anyways
								exists = scope:notification_character.suzerain
								this = scope:notification_character.suzerain
								add = -10
							}
						}
						save_scope_as = ruler_scope
					}
				}
				5 = { #Impressing a vassal
					trigger = {
						any_vassal = {
							harem_politics_grand_consort_task_valid_vassal_trigger = {
								OVERLORD = scope:notification_character
							}
						}
					}
					modifier = {
						NOT = {
							any_tributary = {
								harem_politics_grand_consort_task_valid_tributary_trigger = {
									OVERLORD = scope:notification_character
								}
							}
						}
						add = 3
					}
					#High aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position >= 4
							}
						}	
						add = {
							value = 1
							if = {
								limit = {
									scope:notification_character = {
										any_court_position_holder = {
											type = grand_consort_court_position
											aptitude:grand_consort_court_position = 5
										}
									}
								}
								add = 1
							}
						}
					}

					#Low aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position <= 2
							}
						}	
						add = {
							value = -1
							if = {
								limit = {
									any_court_position_holder = {
										type = grand_consort_court_position
										aptitude:grand_consort_court_position = 1
									}
								}
								add = -1
							}
						}
					}
					modifier = { #Hostile faiths
						any_vassal = {
							OR = {
								faith = {
									faith_hostility_level = {
										target = scope:notification_character.faith
										value >= faith_astray_level
									}
								}	
								is_powerful_vassal_of = scope:notification_character
							}
							harem_politics_grand_consort_task_valid_vassal_trigger = {
								OVERLORD = scope:notification_character
							}
						}
						add = 5
					}
					random_vassal = {
						limit = {
							harem_politics_grand_consort_task_valid_vassal_trigger = {
								OVERLORD = scope:notification_character
							}
						}
						weight = {
							base = 10
							opinion_modifier = { #Opinion
								WHO = this
								opinion_target = scope:notification_character
								multiplier = -0.5
							}
							modifier = { #Faith hostility
								faith = {
									faith_hostility_level = {
										target = scope:notification_character.faith
										value >= faith_astray_level
									}
								}
								add = {
									value = 5
									if = {
										limit = {
											faith = {
												faith_hostility_level = {
													target = scope:notification_character.faith
													value >= faith_hostile_level
												}
											}
										}
										add = 5
									}
								}
							}
							modifier = { #Claimants
								any_claim = {
									tier >= tier_county
									any_de_jure_top_liege = {
										this = scope:notification_character
									}
								}
								add = 5
							}
							modifier = { #Monogamous characters are more intrigued by rulers with many consorts
								hp_accepts_harems = no
								add = 5
							}
							modifier = { #Strong rulers
								max_military_strength >= scope:notification_charactermax_military_strength
								add = 20
							}
							modifier = { #Captured their relative
								has_opinion_modifier = {
									modifier = forced_family_concubine_marriage_opinion
									target = scope:notification_character
								}
								add = 10
							}
							modifier = { #Powerful vassal
								is_powerful_vassal_of = scope:notification_character
								add = 10
							}
							modifier = { #Enemies
								OR = {
									has_relation_rival = scope:notification_character
									has_relation_nemesis = scope:notification_character
								}
								add = 10
							}
							modifier = { #Part of a faction
								is_a_faction_member = yes
								add = {
									value = 10
									if = {
										limit = {
											is_a_faction_leader = yes
										}
										add = 10
									}
								}
							}
						}
						save_scope_as = ruler_scope
					}
				}
				3 = { #Impressing a tributary
					trigger = {
						any_tributary = {
							harem_politics_grand_consort_task_valid_tributary_trigger = {
								OVERLORD = scope:notification_character
							}
						}
					}
					modifier = {
						NOT = {
							any_vassal = {
								harem_politics_grand_consort_task_valid_vassal_trigger = {
									OVERLORD = scope:notification_character
								}
							}
						}
						add = 5
					}
					#High aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position >= 4
							}
						}	
						add = {
							value = 1
							if = {
								limit = {
									scope:notification_character = {
										any_court_position_holder = {
											type = grand_consort_court_position
											aptitude:grand_consort_court_position = 5
										}
									}
								}
								add = 1
							}
						}
					}

					#Low aptitude
					modifier = {
						scope:notification_character = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position <= 2
							}
						}	
						add = {
							value = -1
							if = {
								limit = {
									any_court_position_holder = {
										type = grand_consort_court_position
										aptitude:grand_consort_court_position = 1
									}
								}
								add = -1
							}
						}
					}
					modifier = { #Hostile faiths
						any_tributary = {
							faith = {
								faith_hostility_level = {
									target = scope:notification_character.faith
									value >= faith_astray_level
								}
							}	
							harem_politics_grand_consort_task_valid_tributary_trigger = {
								OVERLORD = scope:notification_character
							}
						}
						add = 5
					}
					random_tributary = {
						limit = {
							harem_politics_grand_consort_task_valid_tributary_trigger = {
								OVERLORD = scope:notification_character
							}
						}
						weight = {
							base = 10
							opinion_modifier = { #Opinion
								WHO = this
								opinion_target = scope:notification_character
								multiplier = -0.5
							}
							modifier = { #Faith hostility
								faith = {
									faith_hostility_level = {
										target = scope:notification_character.faith
										value >= faith_astray_level
									}
								}
								add = {
									value = 5
									if = {
										limit = {
											faith = {
												faith_hostility_level = {
													target = scope:notification_character.faith
													value >= faith_hostile_level
												}
											}
										}
										add = 5
									}
								}
							}
							modifier = { #Claimants
								any_claim = {
									tier >= tier_county
									any_de_jure_top_liege = {
										this = scope:notification_character
									}
								}
								add = 5
							}
							modifier = { #Monogamous characters are more intrigued by rulers with many consorts
								hp_accepts_harems = no
								add = 5
							}
							modifier = { #Strong rulers
								max_military_strength >= scope:notification_charactermax_military_strength
								add = 20
							}
							modifier = { #Captured their relative
								has_opinion_modifier = {
									modifier = forced_family_concubine_marriage_opinion
									target = scope:notification_character
								}
								add = 10
							}
							modifier = { #Enemies
								OR = {
									has_relation_rival = scope:notification_character
									has_relation_nemesis = scope:notification_character
								}
								add = 10
							}
						}
						save_scope_as = ruler_scope
					}
				}
				84 = { #Nothing

				}
			}
			if = {
				limit = {
					exists = scope:ruler_scope
				}
				send_interface_toast = {
					type = event_generic_good
					title = successful_consort_skills_t
					left_icon = scope:ruler_scope
					right_icon = scope:grand_consort_position_holder
					custom_tooltip = successful_consort_on_yearly_skills_desc
					scope:ruler_scope = {
						add_opinion = {
							modifier = impressed_opinion
							target = scope:notification_character
							opinion = 10
						}
					}
				}
			}
		}
	}

	ai_will_do = {
		value = 25
		add = {
			value = "scope:liege.opinion(scope:employee)"
			multiply = 0.1
		}
		value = {
			add = ai_greed
			multiply = -0.4
			max = 20
		}
		# Low aptitude
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position = 1
				}
			}
			add = -25
		}
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position <= 2
				}
			}
			add = -25
		}
		# High aptitude
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position >= 4
				}
			}
			add = 10
		}

		if = {
			limit = {
				NOT = {
					any_consort = {
						is_courtier_of = root
						is_imprisoned = no
						OR = {
							diplomacy >= medium_skill_rating
							learning >= medium_skill_rating
						}
					}
				}
			}
			add = 35
		}

		if = {
			limit = {
				monthly_character_income < monthly_court_position_task_cost_double
			}
			add = -1000
		}
	}
}

grand_consort_task_promote_harmony = {
	court_position_types = { grand_consort_court_position }

	# Monthly cost for the task
	cost = {
		round = no
		prestige = {
			add = {
				value = monthly_court_position_task_cost
				desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
				format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
			}
		}
	}

	is_valid_showing_failures_only = { 
		scope:liege = {
			custom_tooltip = {
				any_consort = {
					is_courtier_of = prev
					is_imprisoned = no
					count >= 3
				}
				text = grand_consort_tasks_consort_limit_tooltip
			}
		}
	}

	base_employer_modifier = {
	}

	scaling_employer_modifiers = {
		terrible = {
			courtier_and_guest_opinion = 1
		}
		poor = {
			stress_loss_mult = 0.03
			courtier_and_guest_opinion = 3
		}
		average = {
			stress_loss_mult = 0.05
			courtier_and_guest_opinion = 5
		}
		good = {
			stress_loss_mult = 0.08
			courtier_and_guest_opinion = 8
		}
		excellent = {
			stress_loss_mult = 0.10
			courtier_and_guest_opinion = 10
		}
	}

	employee_modifier = {
		diplomacy = 2
		stress_gain_mult = 0.15
		owned_personal_scheme_success_chance_growth_add = 10
	}

	on_start = {
		add_character_flag = gc_promoting_harmony
		custom_tooltip = grand_consort_task_promote_harmony_fallback_tt
	}

	on_end = {
		remove_character_flag = gc_promoting_harmony
	}

	ai_will_do = {
		value = 25
		add = {
			value = "scope:liege.opinion(scope:employee)"
			multiply = 0.1
		}
		# Low aptitude
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position = 1
				}
			}
			add = -25
		}
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position <= 2
				}
			}
			add = -25
		}
		# High aptitude
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position >= 4
				}
			}
			add = 10
		}

		if = {
			limit = {
				any_consort = {
					is_courtier_of = root
					OR = {
						any_relation = {
							type = rival
							is_consort_of = root
							is_courtier_of = root
						}
						any_relation = {
							type = nemesis
							is_consort_of = root
							is_courtier_of = root
						}
					}
					count >= 4
				}
			}
			add = 55
		}

		if = {
			limit = {
				monthly_character_income < monthly_court_position_task_cost_double
			}
			add = -1000
		}
	}
}

grand_consort_task_balance_favor = {
	court_position_types = { grand_consort_court_position }

	# Monthly cost for the task
	cost = {
		round = no
		prestige = {
			add = {
				value = monthly_court_position_task_cost
				desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
				format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
			}
		}
	}

	is_valid_showing_failures_only = { 
		scope:liege = {
			custom_tooltip = {
				any_consort = {
					is_courtier_of = prev
					is_imprisoned = no
					count >= 3
				}
				text = grand_consort_tasks_consort_limit_tooltip
			}
			custom_tooltip = {
				NOT = { has_game_rule = consort_favor_off }
				text = grand_consort_tasks_favor_system_off_tooltip
			}
		}
	}

	base_employer_modifier = {
	}

	scaling_employer_modifiers = {
		terrible = {
		}
		poor = {
			stress_loss_mult = 0.05
		}
		average = {
			stress_loss_mult = 0.10
		}
		good = {
			stress_loss_mult = 0.15
		}
		excellent = {
			stress_loss_mult = 0.20
		}
	}

	employee_modifier = {
		fertility = 0.1
		diplomacy = 1
		owned_personal_scheme_success_chance_growth_add = 10
	}

	on_start = {
		add_character_flag = gc_balancing_favor_flag
		custom_tooltip = grand_consort_task_balance_favor_fallback_tt
		scope:liege = {
			if = {
				limit = {
					any_consort = {
						has_character_modifier = favor_boost_modifier
					}
				}
				random_consort = {
					limit = {
						has_character_modifier = favor_boost_modifier
					}
					save_scope_as = favored_consort
				}
				send_interface_toast = {
					type = event_generic_neutral
					title = grand_consort_task_balance_favor.on_start.t
					right_icon = scope:favored_consort
					calyver_stop_favor_boost_effect = {
						CONSORT = scope:favored_consort
						HAREM_LIEGE = scope:liege
					}
				}
			}
		}
	}

	on_end = {
		remove_character_flag = gc_balancing_favor_flag
	}

	ai_will_do = {
		value = 25
		value = {
			add = ai_compassion
			multiply = 0.2
		}
		add = {
			value = "scope:liege.opinion(scope:employee)"
			multiply = 0.10
		}
		# Low aptitude
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position = 1
				}
			}
			add = -25
		}
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position <= 2
				}
			}
			add = -25
		}
		# High aptitude
		if = {
			limit = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position >= 4
				}
			}
			add = 10
		}
		#Traits
		if = {
			limit = {
				has_trait = temperate
			}
			add = 10
		}
		if = { # Diliegnt rulers are more focused on their realm
			limit = {
				has_trait = diligent
			}
			add = -15
		}
		if = { # Chaste characters won't want to spend time with all their consorts
			limit = {
				has_trait = chaste
			}
			add = -15
		}
		# Unfavored consorts
		if = {
			limit = {
				any_consort = {
					is_courtier_of = root
					is_imprisoned = no
					has_variable = favor
					var:favor <= forgotten_consort_upper_limit
					count >= 4
				}
			}
			add = 35
		}
		if = {
			limit = {
				monthly_character_income < monthly_court_position_task_cost_double
			}
			add = -1000
		}
	}
}